home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / scn_savr / scrsvr / biker.txt < prev    next >
Encoding:
Text File  |  1995-11-08  |  4.9 KB  |  94 lines

  1. Creating Screen Savers
  2.  
  3. Overview:
  4.  
  5. Have you ever wanted to write your own screensaver, but was told, "You can't do that in Visual Basic!" In fact, one person I heard 
  6. from told me that Microsoft said that screensavers were impossible in Visual Basic. I didn't believe hem, and this is the result.
  7.  
  8.  
  9. Windows screensavers are easy and fun to write in Visual Basic, but there are some very important things to know.
  10. Experts can go straight to the Code Section of this document.
  11.  
  12.  
  13. Description:
  14.  
  15. Application Title:
  16.  
  17. A Windows screensaver is nothing more that a regular Windows executable file that has been renamed with the .scr extension. 
  18. In Visual Basic, when you are making the executable file, you will need to set the Application Title in the Make EXE dialog box. 
  19. This Application Title MUST be set to "SCRNSAVE  title", where title is the text you want displayed in the Control Panel 
  20. screensaver dropdown box.
  21.  
  22.  
  23.  
  24. Command Line Arguments:
  25.  
  26. When Windows starts up a screensaver it calls it with the "/s" argument, and when it wants to Setup the screensaver it uses the 
  27. "/c" argument. So, we use a code module called Banner.BAS. In Banner.BAS you will see that a Select Case statement 
  28. is used to capture this argument. You will need to change the Startup Form in the options|Project Dialog Box to Sub Main.
  29.  
  30.  
  31.  
  32. Telling Windows that the Saver is Running:
  33.  
  34. How long Windows waits before loading the screensaver is specified in the Control Panel. But if your screensaver doesn't tell 
  35. Windows that it is running, Windows will reload the screensaver after that time passes again, even though the screensaver is 
  36. already running. At first I thought I could remedy this situation by using VB 3.0's App object. The App.PrevInstance property will 
  37. tell you whether or not there is a previous instance loaded.
  38.  
  39.  
  40. This should've worked, and I got many comments saying that I must have messed something up, but it didn't. For some reason, 
  41. with the screensaver this kills both instances, not just the second. But there is a way out. To fix this I found a Windows API call 
  42. which tells Windows that the screensaver is inactive, so don't load one. To use this API you need to use the API call 
  43. SystemParametersInfo. This function is used to change system wide parameters, such as whether or not the screensaver is 
  44. active. Be careful when using this call, since changes are permanent. You will need to make sure that your screensaver turns 
  45. the screensaver back off when it has ended.
  46.  
  47.  
  48. See Sub Main, and Sub ExitNice in the Code Section.
  49.  
  50.  
  51. Hiding The Cursor:
  52.  
  53. When you write a screensaver, you'll want it to hide the mouse cursor as well as whatever else your saver does. To do this you 
  54. need to use the API call -  ShowCursor. When ShowCursor( False ) is called, the cursor is hidden; when ShowCursor( True ) is 
  55. called, the cursor is re-displayed. The Windows cursor is a shared object, so if your process hides it your process needs to 
  56. redisplay it as well. See Code section.
  57.  
  58.  
  59. Knowing when to end:
  60.  
  61. When your screensaver ends is up to you, but generally you'll want it to end if any of the following occur: mouse moves, button 
  62. pressed, key pressed. To do this you will need to call a routine (ExitNice) to exit properly from each of these 
  63. events in your screensaver form.  You need to call this routine because this is where the other half of the 
  64. SystemParametersInfo call is made. If this is left out, the screensaver won't run again after it wakes up. Another problem is that 
  65. the MouseMove message is sent if the cursor is over the form, REGARDLESS if it is moved or not. So, you need to check to 
  66. see if it has moved somehow. See the Code Section for my solution. (Not necessarily the prettiest.
  67.  
  68.  
  69. Config.Frm
  70.  
  71. Windows will pass the "/c" argument to Sub Main if the "Setup" option is chosen from control panel. Here you can setup specific 
  72. options for your screensaver. You might want to save these options in a .ini file (See Windows\Banner.Ini). Its up to you! If your 
  73. Config.Frm has a "Test" feature which starts the screensaver from the Config form, then you will need to be careful about 
  74. remembering to turn on the cursor after the screensaver starts, and then turn it off before it ends. 
  75.  
  76.  
  77. Biker/Banner ScrnSave Forms
  78.  
  79. The programs are setup to test within VB. Follow the inline instructions to make the SCR files
  80.  
  81.  
  82. Disclaimer/Distribution:
  83.  
  84. This information is provided free of charge, and may be freely distributed. If you use portions of this document elsewhere, please 
  85. indicate where you got it. All of the information here has been used and tested by me in Visual Basic 3.0 Professional. Use at 
  86. your own risk. Visual Basic and Microsoft Windows are registered trademarks of Microsoft Corp.
  87.  
  88.  
  89. Full Credit must go to Peter Provost (TT tips article) for his original idea, from which this description is taken.
  90.  
  91. Additional screensaver action code By: Rick Hunt  CS 100307,2062
  92.  
  93.  
  94.